/* 
 *  Copyright (C) 2007 Dip. Ing. dell'Informazione, University of Pisa, Italy
 *  http://info.iet.unipi.it/~cng/ns2voip/
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, USA
 */
/*
 */

#ifndef __NS2_VOIP_SOURCE_H
#define __NS2_VOIP_SOURCE_H

#include <object.h>
#include <t_timers.h>

#include <ranvar.h>

class VoipEncoder;
class RandomVariable;

class VoipBidirectional;

class VoipSource : public TclObject {
public:
        //! Create an empty VoIP source.
        VoipSource ();

        //! Return true if the object is ready to be started.
        bool initialized () {
                return ( encoder_ && talk_ && silence_ ) || bidirectional_; }

        //! Tcl interface.
        /*!
         * Tcl commands:
         * - $obj debug\n
         *   Enable debug to standard error.
         * - $obj nodebug\n
         *   Disable debug to standard error (default).
         * - $obj start\n
         *   Start the first talkspurt generated by this VoIP source.
         * - $obj stop\n
         *   Do not generate any more talkspurts until resumed.
         * - $obj model exponential T S\n
         *   Draw the talkspurt and silence periods randomly from two
         *   exponential distributions with average T and S, respectively.
         * - $obj encoder $enc\n
         *   Bind the VoIP encoder $enc to this object $obj.
         * - $obj bidirectional $bidir\n
         *   Bind the VoIP bidirectional module $bidir to this object $obj.
         */
        virtual int command (int argc, const char*const* argv);

        //! Generate a new talkspurt.
        void handle ();

protected:
        //! Timer to schedule talkspurts.
        /*!
         * The timer is first started via a Tcl command.
         */
        TTimer<VoipSource> timer_;
        //! Pointer to the encoder application.
        VoipEncoder* encoder_;

        //! Pointer to the bidirectional module, if present.
        VoipBidirectional* bidirectional_;

        //! Random variable for talkspurt durations.
        RandomVariable* talk_;

        //! Random variable for silence durations.
        RandomVariable* silence_;

        WeibullRandomVariable talk1_;
        WeibullRandomVariable silence1_;

        //! Talkspurt counter.
        unsigned int count_;
        //! True if debug is enabled.
        bool debug_;
};

#endif // __NS2_VOIP_SOURCE_H
